/*
 * Copyright 2016-present the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.github.pnoker.center.manager.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.pnoker.center.manager.entity.query.DevicePageQuery;
import io.github.pnoker.center.manager.entity.query.RobIdRobNamePageQuery;
import io.github.pnoker.center.manager.mapper.RobIdRobNameMapper;
import io.github.pnoker.center.manager.service.RobIdRobNameService;
import io.github.pnoker.common.exception.NotFoundException;
import io.github.pnoker.common.model.RobIDRobName;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * DeviceService Impl
 *
 * @author pnoker
 * @since 2022.1.0
 */
@Slf4j
@Service
public class RobIdRobNameServiceImpl implements RobIdRobNameService {

    @Resource
    private RobIdRobNameMapper robIdRobNameMapper;

    @Override
    public void add(RobIDRobName entityDO) {

    }

    @Override
    public void delete(String id) {

    }

    @Override
    public void update(RobIDRobName entityDO) {

    }

    @Override
    public RobIDRobName selectById(String id) {
        return null;
    }

    @Override
    public Page<RobIDRobName> list(DevicePageQuery queryDTO) {
        log.error("in robidrobnameServiceImpI DevicePageQuery queryDTO");
        return null;
    }

    @Override
    public RobIDRobName selectByRobId(String robid) {
        System.out.println("IMPL file 5555555");
        RobIdRobNamePageQuery robIdRobNamePageQuery = new RobIdRobNamePageQuery();
        robIdRobNamePageQuery.setRobid(robid);

        // LambdaQueryWrapper<RobIDRobName> queryWrapper =
        // Wrappers.<RobIDRobName>query().lambda();
        QueryWrapper<RobIDRobName> qw = new QueryWrapper<>();
        qw.eq("robid", robid);//查询robid变量等于"robid"列的值
        qw.last("limit 1");//确保只返回符合条件的一条记录
        System.out.println("IMPL file 444444444");
        //robIdRobNameMapper 对象是一个用于执行数据库操作的组件，
        // 使用 selectOne(qw) 方法就是在告诉这个组件去执行按照 QueryWrapper 中条件进行查询，并且只返回一条记录的操作。
        RobIDRobName robIDRobNames = robIdRobNameMapper.selectOne(qw);
        System.out.println(robIDRobNames);

        if (ObjectUtil.isNull(robIDRobNames)) {
            throw new NotFoundException();
        }
        return robIDRobNames;
        //
    }
    //
    //
    // @Override
    // public Page<RobIDRobName> list(RobIdRobNameService queryDTO) {
    // log.error("in robidrobnameServiceImpI RobIdRobNameService queryDTO)");
    // return null;
    // }
    //
    // @Override
    // public Page<RobIDRobName> list(RobIdRobNamePageQuery queryDTO) {
    // return null;
    // }
    //
    // @Override
    // public List<RobIDRobName> list(String robid) {
    // return null;
    // }
    //
    // @Override
    // public List<RobIDRobName> selectByRobId(String robid) {
    //// LambdaQueryWrapper<RobIDRobName> queryWrapper =
    // Wrappers.<RobIDRobName>query().lambda();
    // QueryWrapper<RobIDRobName> qw = new QueryWrapper<>();
    // qw.eq("robid", robid);
    // java.util.List<RobIDRobName> robIDRobNames =
    // robIdRobNameMapper.selectList(qw);
    // if (ObjectUtil.isNull(robIDRobNames)) {
    // throw new NotFoundException();
    // }
    // return robIDRobNames;
    // }

    // @Override
    // public List<Device> selectByDriverId(String driverId) {
    //
    // RobIdRobNamePageQuery robIdRobNamePageQuery = new RobIdRobNamePageQuery();
    // devicePageQuery.setDriverId(driverId);
    // List<Device> devices = deviceMapper.selectList(fuzzyQuery(devicePageQuery));
    // if (ObjectUtil.isNull(devices) || devices.isEmpty()) {
    // throw new NotFoundException();
    // }
    // devices.forEach(device ->
    // device.setProfileIds(profileBindService.selectProfileIdsByDeviceId(device.getId())));
    // return devices;
    // }

}
